package com.moon.game.command.guest.chat;

import java.util.LinkedList;

import com.moon.game.command.BaseCmd;
import com.moon.game.command.RequestSession;
import com.moon.game.exception.GException;
import com.moon.game.manager.PlayerMG;
import com.moon.game.service.ChatService;
import com.moon.game.vos.MsgVo;
import com.moon.game.vos.PlayerVo;

/**
 * @description 查看聊天消息
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-5-31 下午2:09:13
 */
public class GoSendPrivateMsgCmd extends BaseCmd {
	@Override
	protected void runOnce(RequestSession req) throws GException {
		switch (req.getStatus()) {
		case STATU_INIT:
			doInit(req);
			break;
		case STATU_CHECK:
			doCheckSelf(req);
			break;
		case STATU_RETURN:
			doResponse(req);
			break;
		default:
			break;
		}
	}
	
	@Override
	protected void doResponse(RequestSession req) throws GException {
		String[] ps = req.getClientRequest().getPs();
		if (ps == null) {
			doResponsePsError(req);
		}
		String objId = ps[0];
		PlayerVo other = PlayerMG.instance.getPlayer(objId);
		String objName = "";
		if (other != null) {
			objName = other.getName();
		}
		LinkedList<MsgVo> chatList = ChatService.getPrivateMessage(req.getPlayerId());
		req.setVO("obj_name", objName);
		req.setVO("msg_list", chatList);
		req.setVO("obj_id", objId);
		response(req, req.getClientResponse());
	}

}
